package com.ocean.service.library.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ocean.dao.library.BookDao;
import com.ocean.dao.library.LibraryDao;
import com.ocean.entity.library.Book;
import com.ocean.entity.library.Category;
import com.ocean.entity.library.Library;
import com.ocean.service.library.BookService;
import com.ocean.service.library.LibraryService;
import com.ocean.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Project：SchoolManage
 * Package：com.ocean.service.library.impl
 * Author:zy
 * Time:2023/3/3
 */

@Service
public class LibraryServiceImpl implements LibraryService {
    @Autowired
    private LibraryDao libraryDao;


    @Override
    public R save(Library library) {
        if (libraryDao.insert(library) > 0) {
            return R.ok();
        } else {
            return R.fail("插入图书馆失败");
        }
    }

    @Override
    public R queryPage(int page, int size, String name, String description) {
        PageHelper.startPage(page, size);
        PageInfo<Library> pageInfo = new PageInfo<>(libraryDao.selectAllByCondition(name,description));
        return R.ok(pageInfo);
    }

    @Override
    public R delete(int id) {
        if(libraryDao.delete(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R update(Library library) {
        return R.ok(libraryDao.update(library));
    }

    @Override
    public R queryAll() {
        return R.ok(libraryDao.selectAll());
    }


}

